package cn.kgc.airquality.service;

import cn.kgc.airquality.mapper.DistrictMapper;
import cn.kgc.airquality.mapper.QualityMapper;
import cn.kgc.airquality.pojo.District;
import cn.kgc.airquality.pojo.Quality;
import cn.kgc.airquality.pojo.QualityExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class QualityServiceImpl implements  QualityService {
    @Resource
    DistrictMapper districtMapper;
    @Resource
    QualityMapper qualityMapper;
    @Override
    public PageInfo<Quality> selectAll(Integer pageNum, Integer districtid) {
        PageHelper.startPage(pageNum,3);
        List<Quality> qualities=new ArrayList<>();
        if (districtid!=0){
            QualityExample example=new QualityExample();
            QualityExample.Criteria criteria=example.createCriteria();
            criteria.andDistrictidEqualTo(districtid);
            qualities=  qualityMapper.selectByExample(example);
        }else{
            qualities= qualityMapper.selectByExample(null);
        }
        PageInfo<Quality> pageInfo=new PageInfo<>(qualities);
         return pageInfo;
    }

    @Override
    public List<District> selectAllv() {
        List<District> districts = districtMapper.selectByExample(null);
        return districts;
    }
}
